﻿using System;
using System.Collections.Generic;
using System.Text;
using DotNetty.Buffers;
using LitJson;
using NettyDeomo.msg;
using UnityEngine;

namespace NettyDeomo
{
    public class MsgWrapper
    {


        public int id;
        public object msg;


        public IByteBuffer ToByteBuf()
        {
            // string json = JsonUtility.ToJson(msg);
            string json = JsonMapper.ToJson(msg);
            byte[] bytes = Encoding.UTF8.GetBytes(json);
            int len = 8 + bytes.Length;
            IByteBuffer byteBuffer = PooledByteBufferAllocator.Default.Buffer(len);
            byteBuffer.WriteInt(len);
            byteBuffer.WriteInt(id);
            byteBuffer.WriteBytes(bytes);
            return byteBuffer;
        }
    }
}